package com.feng.test.word;

import java.io.File;
import org.jodconverter.JodConverter;
import org.jodconverter.office.*;
import org.jodconverter.ssl.SslConfig;

/**
 * @author HuangSuip
 */
public class WordTest2 {
}

class Word2Pdf2 {

    public static void main(String[] args) {
        File inputFile = new File("E:\\word\\005.docx");
        File outputFile = new File("E:\\word\\005.pdf");
        final LocalOfficeManager officeManager = LocalOfficeManager.install();
        try {
            // Start an office process and connect to the started instance (on port 2002).
            officeManager.start();
            // Convert
            JodConverter
                .convert(inputFile)
                .to(outputFile)
                .execute();
        } catch (OfficeException e) {
            e.printStackTrace();
        } finally {
            // Stop the office process
            OfficeUtils.stopQuietly(officeManager);
        }

    }
}

class Word2Pdf3 {

    public static void main(String[] args) {
        File inputFile = new File("E:\\word\\005.docx");
        File outputFile = new File("E:\\word\\005.pdf");
        final SslConfig sslConfig = new SslConfig();
        sslConfig.setEnabled(true);
        sslConfig.setTrustStore("Path to the TrustStore");
        sslConfig.setTrustStorePassword("Password of the TrustStore");
        OfficeManager manager;
            //manager =OnlineOfficeManager.make("39.108.49.53");
            //manager =  OnlineOfficeManager.install("39.108.49.53");
            manager =new ExternalOfficeManagerBuilder().setConnectOnStart(true).build();
/*
            manager = OnlineOfficeManager.builder()
                               .workingDir("E:\\word")
                               .poolSize(5)
                               .urlConnection("39.108.49.53")
                               .taskExecutionTimeout(20000)
                               .taskQueueTimeout(1000)
                               .build();
*/
        try {
            // Start an office process and connect to the started instance (on port 2002).
            manager.start();
            // Convert
            JodConverter
                .convert(inputFile)
                .to(outputFile)
                .execute();
        } catch (OfficeException e) {
            e.printStackTrace();
        } finally {
            // Stop the office process
            OfficeUtils.stopQuietly(manager);
        }
    }
}
